﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ResourceManager : MonoBehaviour
{
    [SerializeField] public float dirtSource = 100;
    private float maxRes = 1000f;
    private float cannonCost = 100f, teslaCost = 175f;

    private Slider dirtResourceSlider;

    public float regenTime = 640f, regenTimer;
    // Start is called before the first frame update
    void Start()
    {
        dirtResourceSlider = GameObject.Find("ResSlider").GetComponent<Slider>();
    }

    // Update is called once per frame
    void Update()
    {
        dirtResourceSlider.value = dirtSource / maxRes;
        dirtResourceSlider.transform.GetChild(0).GetComponent<Text>().text = dirtSource.ToString();
        regenTimer++;
        if (regenTimer > regenTime)
        {
            dirtSource += 5;
            regenTimer = 0;
        }
    }

    public bool BuildCost(float type)
    {
        if (type == 0)
        {
            //cannon
            float temp = dirtSource - cannonCost;
            if (temp < 0)
            {
                return false;
            }
            else
            {
                dirtSource -= cannonCost;
                return true;
            }
        }
        if (type == 1)
        {
            //tesla
            float temp = dirtSource - teslaCost;
            if (temp < 0)
            {
                return false;
            }
            else
            {
                dirtSource -= teslaCost;
                return true;
            }
        }

        return false;
    }
}
